//
//  UIBarButtons.m
//  LOLBox
//
//  Created by mac on 15-3-27.
//  Copyright (c) 2015年 Honey. All rights reserved.
//

#import "UIBarButtons.h"

@implementation UIBarButtons

- (UIBarButtonItem *)createBackBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setBackgroundImage:[UIImage imageNamed:@"common_back_button"] forState:UIControlStateNormal];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return barBtn;
}
- (UIBarButtonItem *)createCommonBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    NSInteger cnt = arc4random() % 10;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setTitle:[NSString stringWithFormat:@"评%d",cnt] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];

    return barBtn;
}
- (UIBarButtonItem *)createSearchBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"icon_search"] forState:UIControlStateNormal];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

- (UIBarButtonItem *)createDownloadBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setImage:[UIImage imageNamed:@"icon_download"] forState:UIControlStateNormal];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

- (UIBarButtonItem *)createMenuBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setBackgroundImage:[UIImage imageNamed:@"menu_icon"] forState:UIControlStateNormal];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

- (UIBarButtonItem *)createRefreshBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setImage:[UIImage imageNamed:@"newsRefreshBtn"] forState:UIControlStateNormal];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}
//
- (UIBarButtonItem *)createFavBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setImage:[UIImage imageNamed:@"contenttoolbar_hd_fav_light"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"contenttoolbar_hd_fav_selected_light"] forState:UIControlStateSelected];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

- (UIBarButtonItem *)createCancelBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setTitle:@"取消" forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

//添加
- (UIBarButtonItem *)createAddBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setTitle:@"添加" forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;
}

//编辑
- (UIBarButtonItem *)createEditBarButtonWithTarget:(id)target WithAction:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 40);
    [btn setTitle:@"编辑" forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barBtn;

}

//空白
- (UIBarButtonItem *)createSpaceButtonWithWidth:(CGFloat)width
{
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    barBtn.width = width;
    
    return barBtn;
}


@end
